	$(function(){
		initDataGrid();
	});
	function initDataGrid(){
		//创建bootstraptable
		$("#dataGrid").bootstrapTable({
			method:"get",
			cache: false,         
			//缺失无法执行queryParams,传递Page参数
			contentType : "application/x-www-form-urlencoded",
			dataType : "json",
			url : "/gradesign/debt/query",
			queryParams : queryParam,
			pagination : true,//显示分页条：页码，条数等
			striped : true,//隔行变色
			pageNumber : 1,//首页页码
			pageSize : 10,//分页，页面数据条数
			pageList: [10,20,30,40],
			uniqueId : "id",//Indicate an unique identifier for each row
			sidePagination : "server",//在服务器端分页
			height:dataGrid.height,
			sortName : "created_at",
			toolbar : "#toolbar",//工具栏
			columns : [{
				checkbox : "true",
				field : "box",
				width : 50
			},{
				title : "Id",
				field : "id",
				visible : false
			},{
				title : "借款项目",
				field : "item"
			},{
				title : "借款日期",
				field : "date"
			},{
				title : "借款账户",
				field : "account"
			},{
				title : "借款金额",
				field : "money"
			},{
				title : "已还金额",
				field : "paiedmoney"
			},{
				
				title : "待还金额",
				field : "remainmoney"
			},{
				title : "预计还清日期",
				field : "plandate"
			},{
				title : "借款人",
				field : "borrowmember"
			},{
				title : "借出人",
				field : "loanmember"
			},{
				title : "借款类型",
				field : "debttype"
			},{
				title : "备注",
				field : "tip"
			}],
			search : true,
			searchOnEnterkey : true,
			showRefresh : true,
			showToggle : true
		});
	}
	function queryParam(params){
		var param = {
				limit : this.limit,//页面大小
				offset : this.offset,//页码
				pageNumber : this.pageNumber,
				pageSize : this.pageSize,
				sortName : this.sortName,
				sortOrder : this.sortOtder
		};
		return param;
	}	
	//添加借入记录
	function submit() {
	   var params = {};
	   params.type = $("#type").val();
	   params.debtItem = $("#debtItem").val();
	   params.debtDate = $("#debtDate").val();
	   params.debtAccount = $("#debtAccount").val();
	   params.debtMoney = $("#debtMoney").val();
	   params.debtPlanDate = $("#debtPlanDate").val();
	   params.borrowMember = $("#borrowMember").val();
	   params.loanMember = $("#loanMember").val();
	   params.debtTip = $("#debtTip").val();
	   $.ajax({
		   url : "/gradesign/debt/addDebt",
		   data : params,
		   method : "post",
		   dataType : "json",
		   success : function(res){
			   if(res.result=="success"){
				   alert("借款项目添加成功！");
				   document.getElementById("debtModalForm").reset();
				   $("#addBorrowModal").modal('hide');
				   $("#addLoanModal").modal('hide');
				   $("#dataGrid").bootstrapTable('refresh');
			   }else{
				   alert("借款项目添加失败！");
			   }
		   },error : function(){
			   alert("系统错误，请联系管理员");
		   }
	   });
	};
	//添加借出记录
	function submit2() {
	   var params = {};
	   params.type = $("#type2").val();
	   params.debtItem = $("#debtItem2").val();
	   params.debtDate = $("#debtDate2").val();
	   params.debtAccount = $("#debtAccount2").val();
	   params.debtMoney = $("#debtMoney2").val();
	   params.debtPlanDate = $("#debtPlanDate2").val();
	   params.borrowMember = $("#borrowMember2").val();
	   params.loanMember = $("#loanMember2").val();
	   params.debtTip = $("#debtTip2").val();
	   $.ajax({
		   url : "/gradesign/debt/addDebt",
		   data : params,
		   method : "post",
		   dataType : "json",
		   success : function(res){
			   if(res.result=="success"){
				   alert("借款项目添加成功！");
				   document.getElementById("debtModalForm").reset();
				   $("#addBorrowModal").modal('hide');
				   $("#addLoanModal").modal('hide');
				   $("#dataGrid").bootstrapTable('refresh');
			   }else{
				   alert("借款项目添加失败！");
			   }
		   },error : function(){
			   alert("系统错误，请联系管理员");
		   }
	   });
	};
	//删除借款记录
	function deleteDebtItem(){
		var rows = $("#dataGrid").bootstrapTable("getSelections");
		if(rows.length==0){
			alert("请先选中记录！");
		}else{
			var ids = [];
			for(var i = 0;i < rows.length;i++){
				ids.push(rows[i].id);
			}
			$.ajax({
				url : "/gradesign/debt/delete",
				dataType:"json",
				traditional: true,//属性在这里设置
				method:"post",
				data:{
					"ids":ids
				},
				success : function(){
					$("#dataGrid").bootstrapTable("refresh");
					alert("删除成功！");
				},
				error : function(){
					alert("系统错误！");
				}
			})
		}
	};
	//点击修改收入项按钮，判断是否有选中行，然后弹出模态框，并赋值
	function editDebtItem(){
		var row = $("#dataGrid").bootstrapTable("getSelections");
		if(row.length==0){
			alert("请选中要修改的借款项！");
		}else if(row.length==1){
			$('#editDebtModal').modal('show');
			$('#idEdit').val(row[0].id);
			$('#debtItemEdit').val(row[0].item);
			$('#debtDateEdit').val(row[0].date);
			$('#debtAccountEdit').val(row[0].account);
			$('#debtMoneyEdit').val(row[0].money);
			$('#debtPlanDateEdit').val(row[0].plandate);
			$('#borrowMemberEdit').val(row[0].borrowmember);
			$('#loanMemberEdit').val(row[0].loanmember);
			$('#debtTipEdit').val(row[0].tip);
		}else{
			alert("请选中一行要修改的收入项！");
		}
		
	}
	function edit(){
		var params = {};
		   params.id = $("#idEdit").val();
		   params.debtItem = $("#debtItemEdit").val();
		   params.debtDate = $("#debtDateEdit").val();
		   params.debtAccount = $("#debtAccountEdit").val();
		   params.debtMoney = $("#debtMoneyEdit").val();
		   params.debtPlanDate = $("#debtPlanDateEdit").val();
		   params.borrowMember = $("#borrowMemberEdit").val();
		   params.loanMember = $("#loanMemberEdit").val();
		   params.debtTip = $("#debtTipEdit").val();
		   $.ajax({
			   url : "/gradesign/debt/updateItem",
			   data : params,
			   method : "post",
			   dataType : "json",
			   success : function(res){
				   if(res.result=="success"){
					   alert("收入项目修改成功！");
					   document.getElementById("debtModalFormEdit").reset();
					   $("#editDebtModal").modal('hide');
					   $("#dataGrid").bootstrapTable('refresh');
				   }else{
					   alert("收入项目修改失败！");
				   }
			   },error : function(){
				   alert("系统错误，请联系管理员");
			   }
		   });
	};
	$('#datetimepicker').datetimepicker({
	    language:  'zh-CN',
	    weekStart: 1,
	    todayBtn:  1,
	    autoclose: 1,
	    todayHighlight: 1,
	    startView: 2,
	    minView: 2,
	    forceParse: 0,
	    todayHighlight: true
	});
	$('#datetimepicker2').datetimepicker({
	    language:  'zh-CN',
	    weekStart: 1,
	    todayBtn:  1,
	    autoclose: 1,
	    todayHighlight: 1,
	    startView: 2,
	    minView: 2,
	    forceParse: 0,
	    todayHighlight: true
	});
	
	$('#datetimepicker3').datetimepicker({
	    language:  'zh-CN',
	    weekStart: 1,
	    todayBtn:  1,
	    autoclose: 1,
	    todayHighlight: 1,
	    startView: 2,
	    minView: 2,
	    forceParse: 0,
	    todayHighlight: true
	});
	$('#datetimepicker4').datetimepicker({
	    language:  'zh-CN',
	    weekStart: 1,
	    todayBtn:  1,
	    autoclose: 1,
	    todayHighlight: 1,
	    startView: 2,
	    minView: 2,
	    forceParse: 0,
	    todayHighlight: true
	});
	$('#datetimepicker5').datetimepicker({
	    language:  'zh-CN',
	    weekStart: 1,
	    todayBtn:  1,
	    autoclose: 1,
	    todayHighlight: 1,
	    startView: 2,
	    minView: 2,
	    forceParse: 0,
	    todayHighlight: true
	});
	$('#datetimepicker6').datetimepicker({
	    language:  'zh-CN',
	    weekStart: 1,
	    todayBtn:  1,
	    autoclose: 1,
	    todayHighlight: 1,
	    startView: 2,
	    minView: 2,
	    forceParse: 0,
	    todayHighlight: true
	});